﻿using MSSClient;
using MSSClient.Utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using TestDragDropTreeView;
using TestTreeView.Model;
using Zmy.Wpf.CMessageBox;

namespace TestTreeView
{
    /// <summary>
    /// ZsmTreeView.xaml 的交互逻辑
    /// </summary>
    public partial class ZsmTreeView : UserControl
    {
        public delegate void DelItemDelegate(TreeModel delItem);//如果图像被删除了，删除对应的树节点
        public delegate void AddFolderDelegate();//添加文件夹
        public delegate void DeleteDelegate();//删除文件或者文件夹
        public delegate void MoveImageDelegate(TreeModel selectNode, Stuff selectStuff);//转移图像到另外的分组
        public delegate void BreakUpImageDelegate(String groupName);//撤销
        public delegate void ShowGridDelegate();
        public delegate void PriviewImageDelegate();

        public DelItemDelegate delItemDelegateObj;
        public AddFolderDelegate addFolderDelegate;
        public DeleteDelegate deleteDelegate;
        public MoveImageDelegate moveImageDelegate;
        public BreakUpImageDelegate breakUpImageDelegate;
        public PriviewImageDelegate priviewImageDelegate;
        public ShowGridDelegate showGridDelegate;

        public object MainWindow;
        public System.Windows.Controls.Image m_image;

        public List<System.Windows.Controls.Image> imageList;
        //public static TreeModel s_treeModel = null;
        private static TreeModel _selectedTreeModel = null;
        public static TreeModel s_selectedTreeModel
        {
            get
            {
                return _selectedTreeModel;
            }
            set
            {
                _selectedTreeModel = value;
                //findParent(value);
            }
        }

        /// <summary>
        /// 控件数据
        /// </summary>
        private IList<Model.TreeModel> _itemsSourceData;
        
        public ZsmTreeView()
        {
            InitializeComponent();
        }

        public System.Windows.Controls.Image ImageData
        {
            get { return m_image; }
            set { m_image = value; }
        }
        /// <summary>
        /// 控件数据
        /// </summary>
        public  IList<Model.TreeModel> ItemsSourceData
        {
            get { return _itemsSourceData; }
            set
            {
                _itemsSourceData = value;
                tvZsmTree.ItemsSource = _itemsSourceData;
            }
        }

        /// <summary>
        /// 设置对应Id的项为选中状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int SetCheckedById(string id, IList<Model.TreeModel> treeList)
        {
            foreach (var tree in treeList)
            {
                if (tree.Id.Equals(id))
                {
                    tree.IsChecked = true;
                    return 1;
                }
                if (SetCheckedById(id, tree.Children) == 1)
                {
                    return 1;
                }
            }
            return 0;
        }

        /// <summary>
        /// 设置对应Id的项为选中状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int SetCheckedById(string id)
        {
            foreach (var tree in ItemsSourceData)
            {
                if (tree.Id.Equals(id))
                {
                    tree.IsChecked = true;
                    return 1;
                }
                if (SetCheckedById(id, tree.Children) == 1)
                {
                    return 1;
                }
            }
            return 0;
        }

        /// <summary>
        /// 获取选中项
        /// </summary>
        /// <returns></returns>
        public IList<Model.TreeModel> CheckedItemsIgnoreRelation()
        {
            return GetCheckedItemsIgnoreRelation(_itemsSourceData);
        }

        /// <summary>
        /// 私有方法，忽略层次关系的情况下，获取选中项
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private IList<Model.TreeModel> GetCheckedItemsIgnoreRelation(IList<Model.TreeModel> list)
        {
            IList<Model.TreeModel> treeList = new List<Model.TreeModel>();
            foreach (var tree in list)
            {
                if (tree.IsChecked)
                {
                    treeList.Add(tree);
                }
                foreach (var child in GetCheckedItemsIgnoreRelation(tree.Children))
                {
                    treeList.Add(child);
                }
            }
            return treeList;
        }

        public IList<Model.TreeModel> CheckedLevel3Items()
        {
            IList<Model.TreeModel> treeList = new List<Model.TreeModel>();
            foreach (var tree in _itemsSourceData)
            {
                foreach (var child in tree.Children)
                {
                    foreach (var grandchild in child.Children)
                    {
                        if (grandchild.IsChecked)
                        {
                            grandchild.ParentName = child.Name;
                            treeList.Add(grandchild);
                        }
                    }
                }
            }
            return treeList;
        }

        public IList<Model.TreeModel> Level3Items()
        {
            IList<Model.TreeModel> treeList = new List<Model.TreeModel>();
            foreach (var tree in _itemsSourceData)
            {
                foreach (var child in tree.Children)
                {
                    foreach (var grandchild in child.Children)
                    {
                        grandchild.ParentName = child.Name;
                        treeList.Add(grandchild);
                    }
                }
            }
            return treeList;
        }

        public IList<Model.TreeModel> Level2Items()
        {
            IList<Model.TreeModel> treeList = new List<Model.TreeModel>();
            foreach (var tree in _itemsSourceData)
            {
                foreach (var child in tree.Children)
                {
                    child.ParentName = tree.Name;
                    int nCount = 0;
                    foreach (var grandChild in child.Children)
                    {
                        nCount++;
                    }
                    child.ChildrenCount = nCount;
                    child.Type = tree.Id;
                    treeList.Add(child);
                }
            }
            return treeList;
        }

        public IList<Model.TreeModel> CheckedLevel2Items()
        {
            IList<Model.TreeModel> treeList = new List<Model.TreeModel>();
            foreach (var tree in _itemsSourceData)
            {
                foreach (var child in tree.Children)
                {
                    if (child.IsChecked)
                    {
                        int nCount = 0;
                        foreach (var grandChild in child.Children) 
                        {
                            if(grandChild.IsChecked)
                                nCount++;
                        }
                        child.ChildrenCount = nCount;
                        //设置上传的类型，如1是报账单，2是合同等
                        child.Type = tree.Id;
                        treeList.Add(child);
                    }
                }
            }
            return treeList;
        }

        //重命名分组逻辑
        private void menuRename_Click(object sender, RoutedEventArgs e)
        {
            if (tvZsmTree.SelectedItem != null)
            {
                Model.TreeModel tree = (Model.TreeModel)tvZsmTree.SelectedItem;
                if (tree.isBiSaoType.Equals(1))
                {
                    CMessageBox.Show("补单单据不允许修改！", "提示信息", CMessageBoxButton.OKCancel, CMessageBoxImage.None, CMessageBoxDefaultButton.OK);
                    return;
                }
                Model.TreeModel treeParent = tree.Parent;
                IList<Model.TreeModel> treeList = new List<Model.TreeModel>();
                //Model.TreeModel treeNode = treeList.;
                
                Array treeArray = treeList.ToArray();
                RenameDlg dlg = new RenameDlg(tree.Name);
                dlg.Owner = (Window)MainWindow;

                int xuhao = 1;

                dlg.Show();//显示修改弹窗

                dlg.renameDelegateObj += (string renameText) =>
                {
                    foreach (var treeChild in treeParent.Children)
                    {
                        if (treeChild.Name == renameText)
                        {
                            CMessageBox.Show("该 [" + renameText + "] 名称已存在 [" + treeParent.Name + "] 类型中，请重新输入！", "提示信息", CMessageBoxButton.OKCancel, CMessageBoxImage.None, CMessageBoxDefaultButton.OK);
                            return;
                        }
                    }
                    tree.Name = renameText;//父节点名称
                    tree.imageCode = renameText;//父节点imagecode
                    TreeModel parentTree = tree.Parent;
                    foreach (var child in tree.Children)
                    {
                        child.count = xuhao;
                        child.Name = tree.Name +"-" + child.count + CommonUtil.getTreeModelNameTag(child.nameTag);//子节点名称修改
                        child.Type = parentTree.Id;
                        xuhao++;
                    }
                    dlg.Close();
                };
            }
        }

        /// <summary>
        /// 选中所有子项菜单事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectAllOrNotChild_Click(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = VisualUpwardSearch<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
            item.Focus();//选择checkBox时，定位到节点

            //获取选择的节点（定位到的节点）
            Model.TreeModel tree = (Model.TreeModel)tvZsmTree.SelectedItem;

            if (tree.IsChecked)
            {
                tree.SetChildrenChecked(true);
                return;
            }
            if (!tree.IsChecked)
            {
                tree.SetChildrenChecked(false);
                return;
            }
        }
        
        private void menuSelectAllChild_Click(object sender, RoutedEventArgs e)
        {
            if (tvZsmTree.SelectedItem != null)
            {
                Model.TreeModel tree = (Model.TreeModel)tvZsmTree.SelectedItem;
                tree.IsChecked = true;
                tree.SetChildrenChecked(true);
            }
        }

        private void menuCancelAllChild_Click(object sender, RoutedEventArgs e)
        {
            if (tvZsmTree.SelectedItem != null)
            {
                Model.TreeModel tree = (Model.TreeModel)tvZsmTree.SelectedItem;
                tree.IsChecked = false;
                tree.SetChildrenChecked(false);
            }
        }

        /// <summary>
        /// 全部展开菜单事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuExpandAll_Click(object sender, RoutedEventArgs e)
        {
            foreach (Model.TreeModel tree in tvZsmTree.ItemsSource)
            {
                tree.IsExpanded = true;
                tree.SetChildrenExpanded(true);
            }
        }

        /// <summary>
        /// 全部折叠菜单事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuUnExpandAll_Click(object sender, RoutedEventArgs e)
        {
            foreach (Model.TreeModel tree in tvZsmTree.ItemsSource)
            {
                tree.IsExpanded = false;
                tree.SetChildrenExpanded(false);
            }
        }

        /// <summary>
        /// 全部选中事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuSelectAll_Click(object sender, RoutedEventArgs e)
        {
            foreach (Model.TreeModel tree in tvZsmTree.ItemsSource)
            {
                tree.IsChecked = true;
                tree.SetChildrenChecked(true);
            }
        }

        /// <summary>
        /// 全部取消选中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuUnSelectAll_Click(object sender, RoutedEventArgs e)
        {
            foreach (Model.TreeModel tree in tvZsmTree.ItemsSource)
            {
                tree.IsChecked = false;
                tree.SetChildrenChecked(false);
            }
        }

        /// <summary>
        /// 鼠标左键事件 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void TreeViewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            #region
            TreeViewItem tvItem = (TreeViewItem)sender;
            int count = tvItem.Items.Count;
            try
            {
                //TreeView
                TreeViewItem item = VisualUpwardSearch<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;

                TreeModel modelData = (TreeModel)item.Header;
                //Selected data
                s_selectedTreeModel = modelData;
                showGridDelegate();//显示发票信息
                //CommonUtil.WriteLogStr("左键选中Tree_id："+modelData.Id + " level: "+modelData.level, "TreeViewItem_PreviewMouseDown");
                if (item != null && 0 != count)
                {
                    item.Focus();
                    e.Handled = false;

                    if (null != modelData.ImageUrl && !modelData.ImageUrl.Equals(""))
                    {
                        if (!File.Exists(modelData.ImageUrl))
                        {
                            CommonUtil.ShowMsgFrom("选择的节点的图像文件不存在，将删除对应节点！");
                            delItemDelegateObj(modelData);
                            return;
                        }

                        //添加水印
                        // Bitmap testMap = CommonUtil.WaterMarkBitmap(new System.Drawing.Bitmap(modelData.ImageUrl));
                        //testMap.Save("E:\\test.jpg");
                        //m_image.Source = CommonUtil.Bitmap2BitmapImageFromImagrPath("E:\\test.jpg");
                        m_image.Source = CommonUtil.Bitmap2BitmapImageFromImagrPath(modelData.ImageUrl);
                        //imageList = new List<System.Windows.Controls.Image>();
                        //imageList.Add(m_image);
                        //testMap.Dispose();
                        GC.Collect(); //强制回收资源  
                    }
                }
            }
            catch(Exception ex)
            {
                CommonUtil.WriteLog(ex);
                return;
            }
            #endregion
        }
            /// <summary>
            /// 鼠标右键事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
        private void TreeViewItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            TreeViewItem item = VisualUpwardSearch<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;         
            if (item != null)
            {
                item.Focus();
                e.Handled = true;
            }
            TreeModel modelData = (TreeModel)item.Header;
            //MessageBox.Show(modelData.Name);
            s_selectedTreeModel = modelData;
        }

        /// <summary>
        /// 通过勾选框来定位对应的树节点
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <returns></returns>
        static DependencyObject VisualUpwardSearch<T>(DependencyObject source)
        {
            while (source != null && source.GetType() != typeof(T))
                source = VisualTreeHelper.GetParent(source);

            return source;
        }

        private void tvZsmTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            //TreeViewItem item = VisualUpwardSearch<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
            TreeViewItem item = tvZsmTree.SelectedItem as TreeViewItem;
            MessageBox.Show(item.Tag.ToString());
        }

        /// <summary>
        /// 右键显示菜单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tvZsmTree_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            #region
            TreeViewItem item = VisualUpwardSearch<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;

            if (null == item)
            {
                menuAddFolder.Visibility = Visibility.Collapsed;
                moveImage.Visibility = Visibility.Collapsed;
                menuExpandAll.Visibility = Visibility.Collapsed;
                menuUnExpandAll.Visibility = Visibility.Collapsed;
                breakUpImage.Visibility = Visibility.Collapsed;
                menuRename.Visibility = Visibility.Collapsed;
                menuSelectAll.Visibility = Visibility.Collapsed;
                menuUnSelectAll.Visibility = Visibility.Collapsed;
                expolFile.Visibility = Visibility.Collapsed;
                delete.Visibility = Visibility.Collapsed;
                return;
            }
            TreeModel modelData = (Model.TreeModel)tvZsmTree.SelectedItem;
            //一级节点显示
            if (1 == modelData.level)
            {
                menuRename.Visibility = Visibility.Collapsed;
                moveImage.Visibility = Visibility.Collapsed;
                menuRename.Visibility = Visibility.Collapsed;
                breakUpImage.Visibility = Visibility.Collapsed;

                delete.Visibility = Visibility.Visible;
                expolFile.Visibility = Visibility.Visible;
                menuAddFolder.Visibility = Visibility.Visible;
                menuUnExpandAll.Visibility = Visibility.Visible;
                menuSelectAll.Visibility = Visibility.Visible;
                menuUnSelectAll.Visibility = Visibility.Visible;
            }
            //二级节点显示
            if (2 == modelData.level)
            {
                moveImage.Visibility = Visibility.Collapsed;
                menuExpandAll.Visibility = Visibility.Collapsed;
                menuUnExpandAll.Visibility = Visibility.Collapsed;
                breakUpImage.Visibility = Visibility.Collapsed;
                menuAddFolder.Visibility = Visibility.Collapsed;

                delete.Visibility = Visibility.Visible;
                expolFile.Visibility = Visibility.Visible;
                menuRename.Visibility = Visibility.Visible;
                menuSelectAll.Visibility = Visibility.Visible;
                menuUnSelectAll.Visibility = Visibility.Visible;
            }
            //三级节点显示
            if (3 == modelData.level)
            {
                menuAddFolder.Visibility = Visibility.Collapsed;
                menuUnExpandAll.Visibility = Visibility.Collapsed;
                menuSelectAll.Visibility = Visibility.Collapsed;
                menuUnSelectAll.Visibility = Visibility.Collapsed;
                menuExpandAll.Visibility = Visibility.Collapsed;
                menuRename.Visibility = Visibility.Collapsed;

                moveImage.Visibility = Visibility.Visible;
                expolFile.Visibility = Visibility.Visible;
                delete.Visibility = Visibility.Visible;
                breakUpImage.Visibility = Visibility.Visible;
            }
            #endregion
        }

        //导出图片操作
        private void expolFile_Click(object sender, RoutedEventArgs e)
        {
            #region
            System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();
            Model.TreeModel tree = (Model.TreeModel)tvZsmTree.SelectedItem;
            if ( (tree.level == 1 || tree.level == 2) && tree.Children.Count == 0)
            {
                CMessageBox.Show("所选分组没有数据可以导出", "提示信息", CMessageBoxButton.OKCancel, CMessageBoxImage.None, CMessageBoxDefaultButton.OK);
                return;
            }
            if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string filePath = folder.SelectedPath;

                try
                {
                    //导出单张
                    if (3.Equals(tree.level))
                    {
                        if (!File.Exists(filePath + "\\" + tree.Name + ".jpg"))
                        {
                            File.Copy(tree.ImageUrl, filePath + "\\" + tree.Name + ".jpg");
                        }
                    }
                    //导出分组下的图像
                    if (2.Equals(tree.level))
                    {
                        string filePath1 = filePath + "\\" + tree.Name;
                        if (!Directory.Exists(filePath1))//判断文件夹是否存在 
                        {
                            Directory.CreateDirectory(filePath1);//不存在则创建文件夹 
                        }
                        foreach (var treeChild in tree.Children) {
                            if (File.Exists(filePath1 + "\\" + treeChild.Name + ".jpg"))
                            {
                                File.Delete(filePath1 + "\\" + treeChild.Name + ".jpg");
                            }
                            File.Copy(treeChild.ImageUrl, filePath1 + "\\" + treeChild.Name + ".jpg");
                        }
                    }
                    //导出一个类型下的所有分组和图像
                    if (1.Equals(tree.level))
                    {
                        string filePath1 = filePath + "\\" + tree.Name;
                        if (!Directory.Exists(filePath1))//判断文件夹是否存在 
                        {
                            Directory.CreateDirectory(filePath1);//不存在则创建文件夹 
                        }
                        foreach (var treeChild1 in tree.Children)
                        {
                            string filePath2 = filePath1 + "\\" + treeChild1.Name;
                            if (!Directory.Exists(filePath2))//判断文件夹是否存在 
                            {
                                Directory.CreateDirectory(filePath2);//不存在则创建文件夹 
                            }
                            foreach (var treeChild2 in treeChild1.Children)
                            {
                                if (File.Exists(filePath2 + "\\" + treeChild2.Name + ".jpg"))
                                {
                                    File.Delete(filePath2 + "\\" + treeChild2.Name + ".jpg");
                                }
                                File.Copy(treeChild2.ImageUrl, filePath2 + "\\" + treeChild2.Name + ".jpg");
                            }
                        }
                    }
                    CommonUtil.ShowMsgFrom("导出完成！");
                }
                catch (Exception ex)
                {
                    CMessageBox.Show(ex.Message, "提示信息", CMessageBoxButton.OKCancel, CMessageBoxImage.None, CMessageBoxDefaultButton.OK);
                    CommonUtil.WriteLog(ex);
                    return;
                }
            }
            #endregion
        }

        /// <summary>
        /// 初始化时根据屏幕分辨率进行大小适配
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            System.Drawing.Rectangle rect = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
            PrimaryScreen ps = new PrimaryScreen();
            double y = (ps.DpiY + 4) * 0.01;
            double h = rect.Height * 0.9 / y; //高（像素）
            tvZsmTree.Height = h - 90 - 10 ;
        }

        /// <summary>
        /// 界面大小处理
        /// </summary>
        public void changeSize(string type)
        {
            System.Drawing.Rectangle rect = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
            double h = rect.Height; //高(像素)
            if (type == "f")
            {
                tvZsmTree.Height = h * 0.8 - 72 - 44 - 40;
            }
            else
            {
                tvZsmTree.Height = h - 72 - 44 - 40;
            }
        }

        private void menuAddFolder_Click(object sender, RoutedEventArgs e)
        {
            Model.TreeModel tree = (Model.TreeModel)tvZsmTree.SelectedItem;
            if (null == tree)
            {
                CMessageBox.Show("请先选择一个单据类型！", "提示信息", CMessageBoxButton.OKCancel, CMessageBoxImage.None, CMessageBoxDefaultButton.OK);
                return;
            }
            if (null != tree.Parent)
            {
                CMessageBox.Show("现在选择的不是单据类型！", "提示信息", CMessageBoxButton.OKCancel, CMessageBoxImage.None, CMessageBoxDefaultButton.OK);
                return;
            }
            TreeModel newChild = new TreeModel();
            newChild.bizId = DateTime.Now.ToString("yyyyMMddHHmmssffff");
            newChild.Id = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            newChild.Name = "新添加分组_" + DateTime.Now.ToString("sfff");
            newChild.IsExpanded = true;
            newChild.Parent = tree;
            newChild.level = 2;
            newChild.IsSelected = true;
            newChild.IsChecked = true;
            tree.Children.Add(newChild);
            //addFolderDelegate();
        }

        private void delete_Click(object sender, RoutedEventArgs e)
        {
            deleteDelegate();
        }

        private void moveImage_Click(object sender, RoutedEventArgs e)
        {
            Model.TreeModel selectNode = (Model.TreeModel)tvZsmTree.SelectedItem;
            if (selectNode.isBiSaoType.Equals(1) || ZsmTreeView.s_selectedTreeModel.isBuSaoTag.Equals(1))
            {
                CMessageBox.Show("补单任务下的图像不能转移！", "提示信息", CMessageBoxButton.OKCancel, CMessageBoxImage.None, CMessageBoxDefaultButton.OK);
                return;
            }

            IList<TreeModel> t = this.ItemsSourceData;
 
            Window1 g = new Window1(t, selectNode);
            g.Owner = (Window)MainWindow;
            g.Show();
            g.moveImageDelegate += (Stuff selectStuff) =>
            {
                moveImageDelegate(selectNode,selectStuff);
            };
        }

        private void breakUpImage_Click(object sender, RoutedEventArgs e)
        {
            Model.TreeModel selectNode = (Model.TreeModel)tvZsmTree.SelectedItem;
            if (selectNode.isBiSaoType.Equals(1) || ZsmTreeView.s_selectedTreeModel.isBuSaoTag.Equals(1))
            {
                CMessageBox.Show("补单任务下的图像不能拆分！", "提示信息", CMessageBoxButton.OKCancel, CMessageBoxImage.None, CMessageBoxDefaultButton.OK);
                return;
            }
            RenameDlg renameDlg = new RenameDlg("");
            renameDlg.Owner = (Window)MainWindow;
            renameDlg.Show();
            renameDlg.renameDelegateObj += (String groupName) =>
            {
                breakUpImageDelegate(groupName);
                renameDlg.Close();
            };
        }

        //private void TreeViewItem_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        //{
        //    Model.TreeModel selectNode = (Model.TreeModel)tvZsmTree.SelectedItem;
        //    if (selectNode.level.Equals(2))
        //    {
               
        //    }
        //}
    }
}
